//
//  YQSepartionCollectionViewFlowLayout.m
//  MuYing
//
//  Created by tbb on 2019/7/25.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "YQSepartionCollectionViewFlowLayout.h"

@implementation YQSepartionCollectionViewFlowLayout
#pragma mark - 初始化layout的结构和初始需要的参数
- (void)prepareLayout
{
    [super prepareLayout];
}


- (NSArray *) layoutAttributesForElementsInRect:(CGRect)rect {
    NSArray *answer = [super layoutAttributesForElementsInRect:rect];
    
    for(int i = 1; i < [answer count]; ++i) {
        UICollectionViewLayoutAttributes *currentLayoutAttributes = answer[i];
        UICollectionViewLayoutAttributes *prevLayoutAttributes = answer[i - 1];
        NSInteger maximumSpacing = 1;
        NSInteger origin = CGRectGetMaxX(prevLayoutAttributes.frame);
        
        if(origin + maximumSpacing + currentLayoutAttributes.frame.size.width < self.collectionViewContentSize.width) {
            CGRect frame = currentLayoutAttributes.frame;
            frame.origin.x = origin + maximumSpacing;
            //frame.size.width = prevLayoutAttributes.frame.size.width-1;
            currentLayoutAttributes.frame = frame;
        }
    }
    return answer;
}

@end
